#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int g_unval;
int g_val = 100;

int main(int argc, char* argv[], char* env[])
{
	static int test = 10;
	const char* str = "helloworld";
	char* heap_mem1 = (char*)malloc(10);
	char* heap_mem2 = (char*)malloc(10);

	//代码段：可执行代码/只读常量
	printf("code addr: %p\n", main);
	printf("read only string addr: %p\n", str);

	//数据段：全局变量/静态变量
	printf("init global addr: %p\n", &g_val);
	printf("uninit global addr: %p\n", &g_unval);
	printf("test static addr: %p\n", &test);

	//堆：向上增长
	printf("heap addr: %p\n", heap_mem1);
	printf("heap addr: %p\n", heap_mem2);
	
	//栈：向下增长
	printf("stack addr: %p\n", &heap_mem1);
	printf("stack addr: %p\n", &heap_mem2);

	for (int i = 0; i < argc; i++)
		printf("argv[%d]: %p\n", i, argv[i]);
	
	for (int i = 0; env[i]; i++)
		printf("env[%d]: %p\n", i, env[i]);

	return 0;
}
